package star.oath.panel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class DeepSpaceDialog extends JDialog {

    public DeepSpaceDialog(Frame owner) {
        super(owner, "Deep Space Dialog", true); // modal dialog

        // 设置窗口基本属性
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setLayout(new BorderLayout());
        setBackground(new Color(10, 10, 20));

        // 自定义内容面板
        JPanel contentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 20)) {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                // 可选：绘制星空背景（这里简化为纯色）
                g.setColor(new Color(10, 10, 20));
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        contentPanel.setOpaque(true);
        contentPanel.setBackground(new Color(10, 10, 20));
        contentPanel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(85, 85, 255), 2),
                BorderFactory.createEmptyBorder(20, 20, 20, 20)
        ));

        // 创建按钮样式
        JButton button1 = createStyledButton("Confirm");
        JButton button2 = createStyledButton("Cancel");

        contentPanel.add(button1);
        contentPanel.add(button2);

        add(contentPanel, BorderLayout.CENTER);

        // 窗口美化
        getRootPane().setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(85, 85, 255), 1),
                BorderFactory.createEmptyBorder()
        ));

        pack();
        setLocationRelativeTo(owner);
    }

    private JButton createStyledButton(String text) {
        JButton btn = new JButton(text);
        btn.setFocusPainted(false);
        btn.setFont(new Font("Segoe UI", Font.BOLD, 14));

        // 默认状态
        btn.setBackground(new Color(0, 0, 255)); // #00f
        btn.setForeground(Color.WHITE);
        btn.setBorder(BorderFactory.createLineBorder(new Color(85, 85, 255), 2)); // #55f

        // 悬停效果
        btn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                btn.setBackground(new Color(51, 51, 255)); // #33f
            }

            @Override
            public void mouseExited(MouseEvent e) {
                btn.setBackground(new Color(0, 0, 255)); // #00f
            }
        });

        return btn;
    }

    // 测试入口
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 300);
            frame.setVisible(true);

            new DeepSpaceDialog(frame).setVisible(true);
        });
    }
}
